# coding: utf-8
from PySide6.QtWidgets import QWidget
from qfluentwidgets import FluentIcon as FIF, OptionsSettingCard, CustomColorSettingCard, setThemeColor, setTheme, \
    ExpandLayout, SwitchSettingCard

from common import cfg, isWin11, signalBus


class ThemeStyleWidget(QWidget):
    """ Theme style widget. """

    def __init__(self, parent=None):
        super().__init__(parent)
        self.verticalLayout = ExpandLayout(self)
        self.micaCard = SwitchSettingCard(
            FIF.TRANSPARENT,
            self.tr('云母效果'),
            '',
            cfg.micaEnabled,
            self
        )
        self.themeCard = OptionsSettingCard(
            cfg.themeMode,
            FIF.BRUSH,
            self.tr('应用程序的主题'),
            '',
            texts=[self.tr('浅色'), self.tr('深色'), self.tr('跟随系统')],
            parent=self
        )

        self.themeColorCard = CustomColorSettingCard(
            cfg.themeColor,
            FIF.PALETTE,
            self.tr('主题颜色'),
            '',
            self
        )

        self.zoomCard = OptionsSettingCard(
            cfg.dpiScale,
            FIF.ZOOM,
            self.tr('界面缩放'),
            '',
            texts=["100%", "125%", "150%", "175%", "200%", self.tr("跟随系统")],
            parent=self
        )

        self.__initWidgets()

    def __initWidgets(self):
        self.setObjectName('ThemeStyle')
        self.micaCard.setEnabled(isWin11())

        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.addWidget(self.micaCard)
        self.verticalLayout.addWidget(self.themeCard)
        self.verticalLayout.addWidget(self.themeColorCard)
        self.verticalLayout.addWidget(self.zoomCard)

        self.themeColorCard.colorChanged.connect(lambda c: setThemeColor(c))
        cfg.themeChanged.connect(setTheme)
        self.micaCard.checkedChanged.connect(signalBus.micaEnableChanged)
